import axios from '../axios.js';

const prefix = "/api/console";

// 任务列表
const TASK_LIST = "/task/tasklist";
// 任务详情
const TASK_DETAIL = "/task/taskdetail";
// 接单列表
const ACCEPT_LIST = "/task/acceptlist";
// 接单详情
const ACCEPT_DETAIL = "/task/acceptdetail";
// 审核任务
const AUDIT_ACCEPT = "/task/accepcheck";
// 可操作按钮类型
const CAN_HANDLE_BTN = '/task/push/way';
//审核任务列表
const AUDIT_TASK_LIST = '/task/checklist';
// 审核任务
const AUDIT_TASK = '/task/pubcheck';
// 任务相关锁
const TASK_LOCK = '/task/operate/lock';
// 任务投诉列表
const TASK_COMPLAIT_LIST = '/task/report';
// 任务投诉详情
const TASK_COMPLAIT_DETAIL = '/task/report/deal';
// 任务仲裁列表
const TASK_ARBITRATION_LIST = '/task/arbitration/list';
// 任务仲裁详情
const TASK_ARBITRATION_DETAIL = "/task/arbitration/detail";
// 仲裁处理
const TASK_ARBITRATION_DETAIL_DISPOSE = "/task/arbitration/sentence";


// 异常相关
const ABNORMAL_LIST = "/user/abnormal";
const abnormalApi = {
    /**
     *  获取异常列表
     */
    getAbnormalList({page=1,pagesize=10,type,keyword,status}) {
        let resPar = {
            page,
            pagesize,
            status
        };
        if (keyword) {
            resPar.type = type;
            resPar.keyword = keyword;
        }
        return axios.get(prefix + ABNORMAL_LIST,resPar);
    },
    /**
     *  处理异常
     */
    postDisposeAbnormal({id}) {
        return axios.post(prefix + ABNORMAL_LIST,{
            id
        });
    }
};
// 任务分类
const SUBJECT_LIST = "/task/tasktypemange";
// 分类下属项目列表
const SUBJECT_PROJECT_LIST = "/task/projectlist";
// 分类下属项目详情
const SUBJECT_PROJECT_DETAIL = "/task/projecdetail"
const taskSortApi = {
    /**
     *  获取任务分类列表
     */
    getTaskSubjectList({page=1,pagesize=10,keyword}) {
        let resPar = {
            page,
            pagesize
        };
        if (keyword) {
            resPar.keyword = keyword;
        }
        return axios.get(prefix + SUBJECT_LIST,resPar);
    },
    /**
     *  修改任务主题
     */
    postEditTaskSubject(resPar) {
        // let resPar = {
        //     id,
        //     name,
        //     icon,
        //     sort,
        //     status,
        //     count_project_use,
        //     count_task_use,
        //     bid
        // }
        return axios.post(prefix + SUBJECT_LIST,resPar);
    },
    /**
     *  删除任务主题
     */
    deleteTaskSubject({id}) {
        return axios.get(prefix + SUBJECT_LIST,{
            id,
            method: 'delete'
        });
    },
    /**
     *  获取分类下属项目列表
     */
    getProjectListBySubId({page=1,pagesize=10,platform_id,keyword}) {
        let resPar = {
            page,
            pagesize,
            platform_id
        };
        if (keyword) {
            resPar.keyword = keyword;
        }
        return axios.get(prefix + SUBJECT_PROJECT_LIST,resPar);
    },
    /**
     *  获取分类详情
     */
    getProjectDetailById({id}) {
        return axios.get(prefix + SUBJECT_PROJECT_DETAIL,{id});
    },
    /**
     *  修改分类详情
     */
    posetEditProjectDetail({update_data}) {
        return axios.post(prefix + SUBJECT_PROJECT_DETAIL,{update_data});
    },
    /**
     *  修改分类下属项目
     */
    postEditProject({id,status}) {
        return axios.post(prefix + SUBJECT_PROJECT_LIST,{
            id,
            status
        });
    },
    /**
     *  删除分类下属项目
     */
    deleteProject({id}) {
        return axios.get(prefix + SUBJECT_PROJECT_LIST,{
            id,
            method: 'delete'
        });
    },

};
// 发布操作相关
const  PUSH_SET_LSIT = '/task/push/way';
const pushSetApi = {
    getPushSetList() {
        return axios.get(prefix + PUSH_SET_LSIT,{
            array: 'True'
        });
    },
    deletePushSetById({id,type}) {
        return axios.get(prefix + PUSH_SET_LSIT,{
            method: 'delete',
            type: type,
            id
        });
    },
    postEditPushSet({result_target,result_oprations}) {
        return axios.post(prefix + PUSH_SET_LSIT,{
            result_target,
            result_oprations
        });
    }
}
// 系统模板操作相关
const SYSTEM_TEMPKATE_LIST = '/task/templatelist';
const SYSTEM_TEMPKATE_DETAIL = '/task/templateldetail';
const USER_TEMPLATE = '/user/template';
const systemTemplate = {
    getSystemTeplateList({page=1,pagesize=10,keyword}) {
        let resPar = {
            page,
            pagesize
        };
        if (keyword) {
            resPar.keyword = keyword;
        }
        return axios.get(prefix + SYSTEM_TEMPKATE_LIST,resPar);
    },
    deleteSystemTemplate({id}) {
        return axios.get(prefix + USER_TEMPLATE,{
            method: 'delete',
            id
        });
    },
    getSystemTeplateDetail({id}) {
        return axios.get(prefix + SYSTEM_TEMPKATE_DETAIL,{
            id
        });
    },
    postSystemTeplateDetail({id,update_data,bids}) {
        let resPar = {
            id,
            update_data,
            bids
        };
        return axios.post(prefix + SYSTEM_TEMPKATE_DETAIL,resPar);
    }
};
// 用户上传图
const USER_UPLOAD_FILE = '/user/recentfile';
const userUploadFile = {
    getUploadFileList({page =1,pagesize=10,query_time='all',start,end,
        type,keyword,search=0
    }) {
        let resPar = {
            page,
            pagesize,
            query_time,
            search
        };
        if (keyword) {
            resPar.type = type;
            resPar.keyword = keyword;
        }
        if (start && end) {
            resPar.start = start;
            resPar.end = end;
        }
        return axios.get(prefix + USER_UPLOAD_FILE,resPar);
    }
};

let taskApi = {
    /**
     *  获取任务列表
     */
    getTaskList ({page=1,pagesize,type,keyword,id_only,status}) {
        let resPar = {
            page,

        };
        if (pagesize) {
            resPar.pagesize = pagesize;
        }
        if (id_only) {
            resPar.id_only = id_only;
        }
        if (keyword) {
            resPar.type = type;
            resPar.keyword = keyword;
        }
        if (status) {
            resPar.status = status;
        }
        return axios.get(prefix + TASK_LIST,resPar);
    },
    /**
     *  设置任务列表下任务特殊状态
     *  @param { String } id 任务id
     *  @param { String } is_recommand 是否展示 
     *  @param { String } is_top 是否置顶
     */
    postTaskList ({id,is_recommand,is_top}) {
        let resPar = {
            id
        };
        if (typeof is_recommand === 'boolean') {
            resPar.is_recommand = is_recommand;
        }
        if (typeof is_recommand === 'boolean') {
            resPar.is_top = is_top;
        }
        return axios.post(prefix + TASK_LIST,resPar);
    },
    /**
     *  获取任务详情
     * @param { String } id 任务id 
     */
    getTaskDetail  ({id})  {
        let resPar = {
            id,
        };
        return axios.get(prefix + TASK_DETAIL,resPar);
    },
    updateTaskDetail ({id,update_data})  {
        let resPar = {
            update_data
        };
        return axios.post(prefix + TASK_DETAIL,resPar);
    },
    /**
     *   清退相关任务
     */
    repayTaskById ({taskId,status})  {
        return axios.put(prefix + TASK_DETAIL,{
            task_id: taskId,
            status
        });
    },
    /**
     *   获取可操作按钮类型
     */
    getCanHandleBtn ()  {
        return axios.get(prefix + CAN_HANDLE_BTN,{});
    },
    /**
     *   获取接单列表
     */
    getAcceptList ({pagesize,page=1,keyword,type,id_only,status})  {
        let resPar ={
            page
        };
        if (pagesize) {
            resPar.pagesize = pagesize;
        }
        if (keyword) {
            resPar.keyword = keyword;
            resPar.type = type;
        }
        if (id_only) {
            resPar.id_only = id_only;
        }
        if (status) {
            resPar.status = status;
        }
        return axios.get(prefix + ACCEPT_LIST,resPar);
    },
    /**
     *  获取接单详情
     */
    getAcceptDetail ({acceptId})  {
        return axios.get(prefix + ACCEPT_DETAIL,{
            id: acceptId
        });
    },
    /**
     *  审核接单
     */
    postAuditAccept ({id,ischeckok,comment})  {
        let resPar = {
            id,
            ischeckok,
            comment
        };
        return axios.post(prefix + AUDIT_ACCEPT,resPar);
    },
    /**
     *  获取审核任务列表
     */
    getAuditTaskList ({page=1,pagesize,type,keyword})  {
        let resPar = {
            page
        };
        if (pagesize) {
            resPar.pagesize = pagesize;
        }
        if (keyword) {
            resPar.type = type;
            resPar.keyword = keyword;
        }
        return axios.get(prefix + AUDIT_TASK_LIST,resPar);
    },
    /**
     *  审核任务
     */
    postAuditTask ({task_id,status,comment,update_data})  {
        let resPar = {
            task_id,
            status,
            comment,
            update_data
        };
        return axios.post(prefix + AUDIT_TASK,resPar);
    },
    /**
     * 
     * 任务操作锁
     */
    taskOperateLock({id,action,table}) {
        return axios.get(prefix + TASK_LOCK,{
            id,
            action,
            table
        });
    },
    /**
     *   获取任务投诉列表
     */
    getTaskComplaintList ({pagesize=10,page=1,keyword,type,order})  {
        let resPar ={
            page
        };
        if (pagesize) {
            resPar.pagesize = pagesize;
        }
        if (keyword) {
            resPar.keyword = keyword;
            resPar.type = type;
        }
        if (order) {
            resPar.order = order;
        }
        return axios.get(prefix + TASK_COMPLAIT_LIST,resPar);
    },
    /**
     *   获取任务投诉详情
     */
    getTaskComplaintDetail ({task_id})  {
        return axios.get(prefix + TASK_COMPLAIT_DETAIL,{
            task_id
        });
    },
    /**
     *   修改任务投诉参数
     */
    postTaskComplaintDetail ({id,is_show,is_refund})  {
        let resPar = {
            id,
            is_show,
            is_refund
        };
        return axios.post(prefix + TASK_COMPLAIT_DETAIL,resPar);
    },
    /**
     *  获取仲裁列表
     */
    getArbitrationList({page=1,pagesize=10,keyword,type,id_only,status}) {
        let resPar = {
            page
        };
        if (pagesize) {
            resPar.pagesize = pagesize;
        }
        if (keyword) {
            resPar.keyword = keyword;
            resPar.type = type;
        }
        if (id_only) {
            resPar.id_only = id_only;
        }
        if (status) {
            resPar.status = status;
        }
        return axios.get(prefix + TASK_ARBITRATION_LIST,resPar);
    },
    /**
     *  获取仲裁详情
     */
    getArbitrationDetail({id}) {
        let resPar = {
            id
        };
        return axios.get(prefix + TASK_ARBITRATION_DETAIL,resPar);
    },
    /**
     *   处理仲裁
     */
    postDisposeArbitration ({ids,status,remark})  {
        let resPar = {
            ids,
            status,
            remark
        };
        return axios.post(prefix + TASK_ARBITRATION_DETAIL_DISPOSE,resPar);
    },
};
taskApi = Object.assign({},taskApi,abnormalApi,
        taskSortApi,pushSetApi,systemTemplate,userUploadFile);
export default taskApi;